package com.mall.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.dubbo.mapper.SmsCouponProductRelationMapper;
import com.mall.model.domain.SmsCouponProductRelation;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;


/**
 * @author xyiaao
 * @description 针对表【sms_coupon_product_relation(优惠券和产品的关系表)】的数据库操作Api实现
 * @createDate 2022-03-29 19:46:09
 */
@DubboService
public class SmsCouponProductRelationApiImpl extends ServiceImpl<SmsCouponProductRelationMapper, SmsCouponProductRelation>
        implements SmsCouponProductRelationApi {

    @Autowired
    private SmsCouponProductRelationMapper smsCouponProductRelationMapper;

    @Override
    public void deleteByCouponId(Integer id) {

        LambdaQueryWrapper<SmsCouponProductRelation> lqw = new LambdaQueryWrapper<>();
        lqw.eq(id != null, SmsCouponProductRelation::getCouponId, id);
        smsCouponProductRelationMapper.delete(lqw);
    }

    @Override
    public void updateProductRelation(Integer id, SmsCouponProductRelation productRelation) {

        LambdaQueryWrapper<SmsCouponProductRelation> lqw = new LambdaQueryWrapper<>();
        lqw.eq(id != null, SmsCouponProductRelation::getCouponId, id);
        smsCouponProductRelationMapper.update(productRelation, lqw);
    }

    @Override
    public List<SmsCouponProductRelation> findByCouponId(Integer id) {

        LambdaQueryWrapper<SmsCouponProductRelation> lqw = new LambdaQueryWrapper<>();
        lqw.eq(id != null, SmsCouponProductRelation::getCouponId, id);
        return smsCouponProductRelationMapper.selectList(lqw);
    }

}




